package com.example.calculation;

import androidx.appcompat.app.AppCompatActivity;

import android.os.Bundle;
import android.view.View;
import android.widget.EditText;
import android.widget.TextView;

public class subtract extends AppCompatActivity implements View.OnClickListener {

    //将其设为成员变量
    private EditText subtract_1;
    private EditText subtract_2;
    private TextView tv_result;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_subtract);

        tv_result = findViewById(R.id.tv_result);
        subtract_1 = findViewById(R.id.add_1);
        subtract_2 = findViewById(R.id.add_2);
        findViewById(R.id.btn).setOnClickListener(this);
    }

    @Override
    public void onClick(View view) {
        //将输入框的值获取出来且转成字符串形式
        String firstNum = subtract_1.getText().toString();
        String secondNum = subtract_2.getText().toString();
        //计算结果
        double result = Double.parseDouble(firstNum) - Double.parseDouble(secondNum);
        String show = String.valueOf(result);
        //显示在文本框中
        tv_result.setText(show);
        DaoImp imp = new DaoImp();
        imp.add(show);
    }
}